﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：ClientService.cs
// 功能描述：TongTongMall.MallWeb.Application
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Common.AutoMapper;
using TongTongMall.Domain.Repositories.Repositories;
using TongTongMall.Json;
using TongTongMall.MallWeb.Application.Client.Dto;
using TongTongMall.MallWeb.Core.Enums;
using TongTongMall.MallWeb.Core.Identitys;

using TongTongMall.Redis.Cache;
using TongTongMall.Redis.Cache.Configuration;
using TongTongMall.UI;

namespace TongTongMall.MallWeb.Application.Client
{
    public class ClientService : MallWebApplicationServiceBase, IClientService
    {
        private readonly IRepository<Core.Authorization.Client, long> _clientRepository;


        /// <summary>
        /// redis的配置内容
        /// </summary>
        public IRedisConfiguration RedisConfigurationManager { get; set; } = RedisConfiguration.Default;

        private readonly IRedisCache _redisCache;
        public ClientService(
            IRepository<Core.Authorization.Client, long> _clientRepository,
            IRedisCache _redisCache)
        {
            this._clientRepository = _clientRepository;
            this._redisCache = _redisCache;
        }

        /// <summary>
        /// 延时缓存
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public Task Delayed(string keys)
        {
            throw new NotImplementedException();
        }

        public async Task<ClientDto> Get(string username)
        {
            var model = await _clientRepository.FirstOrDefaultAsync(new { Name = username });
            var clientData = model.MapTo<ClientDto>();
            return clientData;
        }

        public Task TransferCache(string sessionKey, long userId, long tenantId, string tenantName)
        {
            return Task.FromResult(0);

        }
    }
}
